<template>
  <el-select
      v-model="optionValue"
      filterable clearable
      placeholder="请选择机构分类"
  >
      <el-option
          v-for="item in lists"
          :key="item.id"
          :label="item.title"
          :value="item.id"
      >
      </el-option>
  </el-select>
</template>

<script>
import { getOrganizationTypeAll } from "../../api/organizationType";
export default {
  props: {
      nowValue: {
          type: [Number,String],
          default: ''
      },
      type_id: {
          type: [Number],
          default: 0
      }
  },
  data() {
      return {
          lists: [],
          optionValue: 0
      };
  },
  created(){
    this.setList();
    this.optionValue = this.nowValue;
  },
  watch: {
      nowValue(newValue) {
          this.optionValue = newValue;
      },
      optionValue(newValue) {
          this.$emit("update:nowValue", newValue);
      },
      type_id(newValue) {
        this.setList(newValue);
      }
  },
  methods: {
    async setList(){
            let response = await getOrganizationTypeAll();
            if(response.status == 200 && response.data.data){
                this.lists = response.data.data;
            }
        }
  }
};
</script>
